/*
 * @Author: linZeJian
 * @Date: 2022-04-22 16:11:08
 * @LastEditors: linZeJian
 * @LastEditTime: 2022-04-22 16:48:48
 * @Description: 
 */

import axios from 'axios'

const request = axios.create({
  // 请求有配baseURL则代替下面的默认配置项baseURL
  baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 30000, // request timeout
  withCredentials: false
})

function getToken() {
  return localStorage.getItem("messageId")
}

request.interceptors.request.use(
  config => {
    config.headers['test-user-id'] = "e8458684-7572-4130-b63b-a5c538ba8898"
    // if (getToken()) {
    //     config.headers['Authorization'] = getToken()
    // }
    return config
  },
  error => {
    return Promise.reject(new Error(error).message)
  }
)

request.interceptors.response.use(
  response => {
    return response.data
  },
  error => {
    return Promise.reject(new Error(error).message)
  }
)

export default request
